/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 *(C) Copyright 2006 Marvell International Ltd.  
 * All Rights Reserved 
 */

#ifndef __XLLP_KEYPAD_PROC_H
#define  __XLLP_KEYPAD_PROC_H
#include    "xllp_defs.h"

/* Bit Definitions for KeyPad Interface Control Register */

#define     DIRECT_KP_INTR_ENABLE       (0x1    <<  0)
#define     DIRECT_KP_ENABLE            (0x1    <<  1)
#define     ROTARY_ENCODER_0_ENABLE     (0x1    <<  2)
#define     ROTARY_ENCODER_1_ENABLE     (0x1    <<  3)
#define     ROTARY_ENCODER_ZERO_DEB     (0x1    <<  4)
#define     DIRECT_INTR_BIT         (0x1    <<  5)
#define     DIRECT_KEY_NUMS         (0x2  <<  6)   
#define     DIRECT_DEBOUNCE_BIT         (0x1    <<  9)
#define     MATRIX_INTR_ENABLE          (0x1    <<  11)
#define     MATRIX_KP_ENABLE            (0x1    <<  12)
#define     IGNORE_MULTIPLE_KEY_PRESS       (0x1    <<  21)
#define     MATRIX_INTR_BIT         (0x1    <<  22)
#define     AUTO_SCAN_ON_ACTIVITY       (0x1    <<  29)
#define     AUTO_SCAN_BIT           (0x1    <<  30)
#define     MAT_SCAN_LINE0          (0x1    <<  13)
#define     MAT_SCAN_LINE1          (0x1    <<  14)
#define     MAT_SCAN_LINE2          (0x1    <<  15)
#define     MAT_SCAN_LINE3          (0x1    <<  16)
#define     MAT_SCAN_LINE4          (0x1    <<  17)
#define     MAT_SCAN_LINE5          (0x1    <<  18)
#define     MAT_SCAN_LINE6          (0x1    <<  19)
#define     MAT_SCAN_LINE7          (0x1    <<  20)

/* Bit Definitions for KeyPad Interface Direct Key Register */

#define     DIRECT_KEY_PRESSED          (0x1    <<  31)
#define     DIRECT_KEY_IN_7         (0x1    <<  7)
#define     DIRECT_KEY_IN_6         (0x1    <<  6)
#define     DIRECT_KEY_IN_5         (0x1    <<  5)
#define     DIRECT_KEY_IN_4         (0x1    <<  4)
#define     DIRECT_KEY_IN_3         (0x1    <<  3)
#define     DIRECT_KEY_IN_2         (0x1    <<  2)
#define     ROTARY_ENC_0_SENSOR_B       (0x1    <<  1)
#define     ROTARY_ENC_0_SENSOR_A       (0x1    <<  0)
#define     DIRECT_KEY_NUMS_MIN_1       (0x1    <<  6) 

/* Bit Definitions for KeyPad Encoder Count Register */

#define     UNDERFLOW_ROTARY_ENC_0      (0x1    <<  14)
#define     OVERFLOW_ROTARY_ENC_0       (0x1    <<  15)

/* Bit Definitions for KeyPad Interface Matrix Key Register */

#define     MATRIX_KEY_PRESSED          (0x1    <<  31)
#define     MATRIX_ROW_MASK         0xFF

/* Bit Definitions for KeyPad Interface Automatic Scan Register */

#define     SCAN_ON_BIT             (0x1    <<  31)
#define     ROW_SELECTED_MASK           0xF0
#define     COL_SELECTED_MASK           0x0F
#define     MULTI_KEYS_PRESS            0x7C000000
#define     SINGLE_KEY_PRESS            (0x1    <<  26)

/* 
Bit Definitions for KeyPad Interface Automatic Scan Multiple 
Key Press Register 0,1,2,3
*/

#define     MATRIX_KP_COL_EVEN_MASK     0x0000FF
#define     MATRIX_KP_COL_ODD_MASK      0xFF0000                    
#define     XLLP_KP_INVALID_ROW         0xFF

/* 
KeyPad controller supports 3 modes of operation. 
All three will be tested but the default
mode shall be AUTO_SCAN_ON_ACT 
*/
#define     MANUAL_MATRIX_SCAN      0
#define     AUTO_SCAN_ON_ACT        1           
#define     AUTO_SCAN_BY_AS_BIT     2

#define     NOT_AVAILABLE       0
#define     AVAILABLE           1
#define     COUNT_MASK          0xFF

#define     START_VALUE         0x7F

/* legacy scan code symbols */
#define     SCAN_CODE_MASK      0xFF
#define     NO_KEY          0xFF
#define     SCAN_CODE_SCROLL_UP     0xA
#define     SCAN_CODE_SCROLL_DOWN   0xB
#define     SCAN_CODE_ACTION        0xC

/* New navigation-station chord scan codes*/

#define     XLLP_KP_SC_N_UP_LEFT        0xA5 
#define     XLLP_KP_SC_N_UP_RIGHT       0xA6 
#define     XLLP_KP_SC_N_DOWN_LEFT      0xA7 
#define     XLLP_KP_SC_N_DOWN_RIGHT     0xA8 
#define     XLLP_KP_SC_N_ACTION_UP      0xA9 
#define     XLLP_KP_SC_N_ACTION_DOWN        0xAA 
#define     XLLP_KP_SC_N_ACTION_LEFT        0xAB 
#define     XLLP_KP_SC_N_ACTION_RIGHT       0xAC 
#define     XLLP_KP_SC_N_ACTION_UP_LEFT     0xAD 
#define     XLLP_KP_SC_N_ACTION_UP_RIGHT    0xAE 
#define     XLLP_KP_SC_N_ACTION_DOWN_LEFT   0xAF 
#define     XLLP_KP_SC_N_ACTION_DOWN_RIGHT  0xB5 

typedef struct
{
    XLLP_VUINT32_T  kpControlReg;
    XLLP_VUINT32_T  rsvd1;
    XLLP_VUINT32_T  kpDirectKeyReg;
    XLLP_VUINT32_T  rsvd2;
    XLLP_VUINT32_T  kpRotaryEncoderCountReg;
    XLLP_VUINT32_T  rsvd3;
    XLLP_VUINT32_T  kpMatrixKeyReg;
    XLLP_VUINT32_T  rsvd4;
    XLLP_VUINT32_T  kpAutomaticScanReg;
    XLLP_VUINT32_T  rsvd5;
    XLLP_VUINT32_T  kpAutoScanMultiKeyPress0;
    XLLP_VUINT32_T  rsvd6;
    XLLP_VUINT32_T  kpAutoScanMultiKeyPress1;
    XLLP_VUINT32_T  rsvd7;
    XLLP_VUINT32_T  kpAutoScanMultiKeyPress2;
    XLLP_VUINT32_T  rsvd8;
    XLLP_VUINT32_T  kpAutoScanMultiKeyPress3;
    XLLP_VUINT32_T  rsvd9;
    XLLP_VUINT32_T  kpKeyDebounceInterval;

} XLLP_KEYPAD_REGS;

/*maximum number of keys that can be detected simultaneously*/
#define  DEFAULT_DIRECT_DEBOUNCE_MS  30
#define  DEFAULT_MATRIX_DEBOUNCE_MS  30

#ifdef __cplusplus
extern "C"{
#endif 

extern XLLP_STATUS_T read_scan_code_automatically(
            XLLP_KEYPAD_REGS *v_pkeypad_regs,
            XLLP_UINT8_T    *key_index);
extern XLLP_STATUS_T  read_direct_keys(
            XLLP_KEYPAD_REGS *v_pkeypad_regs,
            XLLP_UINT8_T *key);
extern void xllp_keypad_config_controller(
            XLLP_KEYPAD_REGS *  p_key_pad_regs, 
            XLLP_BOOL_T use_default_debounces, 
            XLLP_UINT8_T    matix_debounce_ms, 
            XLLP_UINT8_T    direct_debounce_ms,
            XLLP_UINT8_T    max_row,
            XLLP_UINT8_T    max_col);

#ifdef __cplusplus
}
#endif

#endif

